<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CreateProductFieldValuesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (!Schema::hasTable('product_field_values')) {
            Schema::create('product_field_values', function (Blueprint $table) {
                $table->integer('cate_id')->comment('商品品类ID:product_catgories.id');
                $table->integer('product_id')->comment('商品ID:product_bases.id');
                $table->integer('field_id')->comment('字段ID:product_catgory_values.id');
                $table->string('name', 64)->comment('字段标识名,英文');
                $table->string('label', 64)->comment('字段中文名');
                $table->mediumText('content')->nullable()->comment('字段内容');
                $table->timestamps();
                $table->index(['cate_id', 'product_id']);
            });
            DB::statement("ALTER TABLE `product_field_values` comment '商品扩展字段值表'");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('product_field_values');
    }
}
